"""
留言相关的Pydantic模式
"""
from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field, EmailStr

class MessageBase(BaseModel):
    """留言基础模式"""
    name: str = Field(..., max_length=100, description="姓名")
    phone: str = Field(..., max_length=50, description="电话")
    email: Optional[str] = Field(None, max_length=100, description="邮箱")
    subject: Optional[str] = Field(None, max_length=200, description="主题")
    message: str = Field(..., description="留言内容")

class MessageCreate(MessageBase):
    """创建留言请求模式"""
    class Config:
        json_schema_extra = {
            "example": {
                "name": "张三",
                "phone": "13800138000",
                "email": "zhangsan@example.com",
                "subject": "环境评估咨询",
                "message": "我们公司需要进行环境影响评估，希望了解相关服务和费用。"
            }
        }

class MessageUpdate(BaseModel):
    """更新留言模式"""
    is_read: Optional[bool] = Field(None, description="是否已读")
    is_replied: Optional[bool] = Field(None, description="是否已回复")
    reply_content: Optional[str] = Field(None, description="回复内容")

class MessageResponse(MessageBase):
    """留言响应模式"""
    id: int
    is_read: bool
    is_replied: bool
    reply_content: Optional[str]
    reply_time: Optional[datetime]
    created_at: datetime
    updated_at: Optional[datetime]

    class Config:
        from_attributes = True

class MessageListResponse(BaseModel):
    """留言列表响应模式"""
    items: list[MessageResponse]
    total: int
    page: int
    size: int
    pages: int

class MessageStatsResponse(BaseModel):
    """留言统计响应模式"""
    total: int = Field(..., description="总留言数")
    unread: int = Field(..., description="未读留言数")
    unreplied: int = Field(..., description="未回复留言数")
    today: int = Field(..., description="今日新增留言数")
